package com.bitmain.mmst.miner.monitor.helper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bitmain.mmst.common.util.SpringContextHolder;
import com.bitmain.mmst.domain.MinerDetectBatch;
import com.bitmain.mmst.domain.MinerDetectDetail;
import com.bitmain.mmst.domain.MinerDetectFailure;
import com.bitmain.mmst.domain.MinerShelf;
import com.bitmain.mmst.web.dao.MonitorDao;

/**
 * 
 *
 * @author Richard - rui.wu@bitmain.com
 * @since 2016年7月13日
 *
 */
public class DetectDataHelper {
	private static MonitorDao monitorDao = SpringContextHolder.getBean("monitorDao",MonitorDao.class);
	
	public static List<MinerShelf> fetchAllShelfs() {
		List<MinerShelf> shelfs = monitorDao.selectAllShelfs(); 
		return shelfs;
	}

	public static void saveDetail(MinerDetectDetail detail) {
		System.out.println("minerShelfId:"+detail.getMinerShelfId());
		System.out.println("minerHost:"+detail.getMinerHost());
		System.out.println("minerMac:"+detail.getMinerMac());
		monitorDao.insertDetail(detail);
	}

	public static boolean detailTableExists(int date) {
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("date", date);
		return monitorDao.countDetailTable(params)>0;
	}

	public static void createDetailTable(int date,long dateBeginning,long dateEnd) {
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("date", date);
		params.put("dateBeginning", dateBeginning);
		params.put("dateEnd", dateEnd);
		monitorDao.createDetailTable(params);
	}

	public static void saveFailure(MinerDetectFailure failure) {
		monitorDao.insertFailure(failure);
	}

	public static void saveBatch(MinerDetectBatch batch) {
		monitorDao.insertBatch(batch);
	}
}
